package com.playwright.util.course;

import com.microsoft.playwright.*;

/**
 * @author liyanhao
 * @Date 2024-01-04 10:17
 */
public class 自定义录制 {

//    public static void main(String[] args) {
//        try (Playwright playwright = Playwright.create()) {
//            Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions()
//                    .setHeadless(false));
//            BrowserContext context = browser.newContext();
//            Page page = context.newPage();
//            page.navigate("https://mms.pinduoduo.com/act-bidding/market-sign-list?activity_status=ALL");
//
//            page.getByPlaceholder("请输入账号名/手机号").click();
//            page.getByPlaceholder("请输入账号名/手机号").click(new Locator.ClickOptions()
//                    .setModifiers(Arrays.asList(KeyboardModifier.CONTROL)));
//            page.getByPlaceholder("请输入账号名/手机号").fill("真责数码实在智能");
//            page.getByPlaceholder("请输入密码").click();
//            page.getByPlaceholder("请输入密码").fill("SZzn123456");
//            page.getByTestId("beast-core-button").click();
//            page.getByText("活动中").click();
//        }
//    }
    public static void main(String[] args) throws InterruptedException {

        try (Playwright playwright = Playwright.create()) {
            BrowserType chromium = playwright.chromium();
            Browser browser = chromium.connectOverCDP("http://127.0.0.1:" + 49423); // 填写环境的debuggingPort参数
//            BrowserContext context = browser.contexts().get(0);

            BrowserContext context = browser.newContext(/* pass any options */);
            Page page = context.newPage();
            page.navigate("https://mms.pinduoduo.com/act-bidding/market-sign-list?activity_status=ALL");
            System.out.println(page.title());

            page.waitForLoadState();
            Thread.sleep(10000l);
            //mvn exec:java -e -D exec.mainClass=com.microsoft.playwright.CLI -D exec.args="codegen github.com/microsoft/playwright  --save-storage=auth.json"

        }

    }

    private static void extracted() {
        try (Playwright playwright = Playwright.create()) {
            BrowserType chromium = playwright.chromium();
            // Make sure to run headed.
            Browser browser = chromium.launch(new BrowserType.LaunchOptions().setHeadless(false));
            // Setup context however you like.
            BrowserContext context = browser.newContext(/* pass any options */);
            context.route("**/*", route -> route.resume());
            // Pause the page, and start recording manually.
            Page page = context.newPage();
            page.pause();
        }
    }
}
